package com.eds.controller;

import com.eds.exception.BusException;
import com.eds.pojo.CodeEnum;
import com.eds.service.TeacherScheduleService;
import com.pojo.TeacherSchedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName：TeacherController
 * @Author: vvSmile
 * @Date: 2025/03/27
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@RestController
@RequestMapping("/teacherController")
public class TeacherController {
    @Autowired
    private TeacherScheduleService teacherScheduleService;


    //处理课程安排数据
    @PostMapping("/insertSchedule")
    boolean insertSchedule(@RequestBody TeacherSchedule schedule) {
        Boolean insertScheduleReturn = teacherScheduleService.insertSchedule(schedule);
        return insertScheduleReturn;
    }


    //查询课程时间
    @GetMapping("/selectTeacherSchedules")
    List<TeacherSchedule> selectTeacherSchedules(Long courseId) {
        List<TeacherSchedule> teacherSchedules = teacherScheduleService.selectTeacherSchedules(courseId);
        return teacherSchedules;
    }


    //更新课程时间状态为-1
    @GetMapping("/updateScheduleStatusDel")
    Boolean updateScheduleStatusDel(@RequestParam("courseId") Long courseId) {
        Boolean updateScheduleStatusDelReturn = teacherScheduleService.updateScheduleStatusDel(courseId);
        return updateScheduleStatusDelReturn;
    }


    //更新课程时间信息
    @PostMapping("/updateScheduleInfo")
    boolean updateScheduleInfo(@RequestBody TeacherSchedule teacherSchedule) {
        Boolean updateScheduleInfoReturn = teacherScheduleService.updateScheduleInfo(teacherSchedule);
        if (!updateScheduleInfoReturn) {
            throw new BusException(CodeEnum.UPDATE_COURSE_SCHEDULE_INFO_ERROR.getCode(), CodeEnum.UPDATE_COURSE_SCHEDULE_INFO_ERROR.getMessage());
        }
        return updateScheduleInfoReturn;
    }


    //删除所有的Schedule
    @DeleteMapping("/deleteAllSchedule")
    int deleteAllSchedule(Long courseId) {
        int deleteAllScheduleReturn = teacherScheduleService.deleteAllSchedule(courseId);
        return deleteAllScheduleReturn;
    }

    //查询课程时间
    @GetMapping("/selectTeacherSchedulesByScheduleId")
    TeacherSchedule selectTeacherSchedulesByScheduleId(Long scheduleId) {
        TeacherSchedule teacherSchedule = teacherScheduleService.selectTeacherSchedulesByScheduleId(scheduleId);
        return teacherSchedule;
    }

    //更新课程时间状态为-1
    @PostMapping("/updateScheduleStatusReverseBooking")
    Boolean updateScheduleStatusReverseBooking(@RequestBody TeacherSchedule teacherSchedule) {
        Boolean updateScheduleStatusReverseBookingReturn = teacherScheduleService.updateScheduleStatusReverseBooking(teacherSchedule);
        return updateScheduleStatusReverseBookingReturn;
    }

    @GetMapping("/selectCourseIdByScheduleId")
    TeacherSchedule selectCourseIdByScheduleId(@RequestParam("scheduleId") Long scheduleId) {
        TeacherSchedule schedule = teacherScheduleService.selectCourseIdByScheduleId(scheduleId);
        return schedule;
    }

    //删除课程安排
    @DeleteMapping("/delSchedule")
    Boolean delSchedule(@RequestBody TeacherSchedule teacherSchedule) {
        Boolean delScheduleReturn = teacherScheduleService.delSchedule(teacherSchedule);
        return delScheduleReturn;
    }

    //根据课程安排查询课程安排
    @PostMapping("/selectTeacherSchedulesBySchedule")
    TeacherSchedule selectTeacherSchedulesBySchedule(@RequestBody TeacherSchedule teacherSchedule) {
        TeacherSchedule teacherScheduleReturn = teacherScheduleService.selectTeacherSchedulesBySchedule(teacherSchedule);
        return teacherScheduleReturn;
    }

    //根据课程安排和用户ID查询课程安排
    @PostMapping("/selectTeacherSchedulesByScheduleAndUserId")
    TeacherSchedule selectTeacherSchedulesByScheduleAndUserId(@RequestBody TeacherSchedule teacherSchedule) {
        TeacherSchedule teacherScheduleReturn = teacherScheduleService.selectTeacherSchedulesByScheduleAndUserId(teacherSchedule);
        return teacherScheduleReturn;
    }

    //查询课程安排
    @GetMapping("/selectTeacherSchedulesByUserId")
    List<TeacherSchedule> selectTeacherSchedulesByUserId(@RequestParam("scheduleId") Long userId) {
        return teacherScheduleService.selectTeacherSchedulesByUserId(userId);
    }


    //更新课程安排状态
    @GetMapping("/updateScheduleStatus")
    int updateScheduleStatus(@RequestParam("scheduleId") Long scheduleId, @RequestParam("status") int status) {
        int updateScheduleStatus = teacherScheduleService.updateScheduleStatus(scheduleId, status);
        return updateScheduleStatus;
    }
}
